<template>
  <page-header-wrapper>
    <global-search :list="searchList" @search="handleSearch" @reset="handleReset"> </global-search>
    <a-card :bordered="false">
      <s-table
        ref="table"
        size="default"
        rowKey="ID"
        :columns="columns"
        :data="loadData"
        :scroll="{ x: true }"
        :pagination="{ showTotal: (total) => `共 ${total} 条` }"
      >
        <div slot="tabAction">
          <y-button icon="plus" type="primary" @click="handleAction({}, 'add')">新增减免政策</y-button>
        </div>
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }} </span>
        <span slot="time" slot-scope="text">{{ text | moment }}</span>
        <ellipsis :length="36" slot="ellipsis" slot-scope="text">{{ text }}</ellipsis>
        <div slot="action" slot-scope="text, record">
          <y-button type="link" @click="handleAction(record, 'detail')">查看</y-button>
          <y-button type="link" @click="handleAction(record, 'edit')">编辑</y-button>
          <a-popconfirm
            placement="left"
            :title="`是否${record.WhetherExecutioOrZF === '0' ? '作废' : '启用'}此租金减免政策`"
            @confirm="handleAction(record, 'state')"
          >
            <y-button type="link" :class="record.WhetherExecutioOrZF === '0' ? 'text-error' : 'text-warning'">{{
              record.WhetherExecutioOrZF === '0' ? '作废' : '启用'
            }}</y-button>
          </a-popconfirm>
        </div>
      </s-table>
    </a-card>
    <rent-form :visible.sync="visibleForm" :data.sync="editData" @success="tableRefresh"></rent-form>
    <detail :visible.sync="visibleDetail" :data.sync="editData"> </detail
  ></page-header-wrapper>
</template>

<script>
import { STable, Ellipsis } from '@/components'
import { getRentReductStandardManage, postRentReductStandardManage } from '@/api/followUpManagement'
import rentForm from './components/form.vue'
import detail from './components/detail.vue'
export default {
  name: 'cityComplexInquireList',
  components: {
    STable,
    Ellipsis,
    rentForm,
    detail,
  },
  data() {
    return {
      searchList: [
        {
          label: '标准名称',
          fields: 'standardName',
          type: 'input',
          props: {
            placeholder: '请输入标准名称',
          },
        },
      ],
      queryParam: {
        classType: '租金减免政策',
        standardName: '',
      },
      columns: [
        {
          title: '序号',
          align: 'center',
          width: '80px',
          scopedSlots: { customRender: 'index' },
        },
        {
          title: '标准名称',
          align: 'center',
          dataIndex: 'StandardName',
        },
        {
          title: '辅助说明',
          align: 'center',
          dataIndex: 'AuxiliaryExplain',
          scopedSlots: { customRender: 'ellipsis' },
        },
        {
          title: '减免对象',
          align: 'center',
          dataIndex: 'ReductionObject',
        },
        {
          title: '收取比例',
          align: 'center',
          dataIndex: 'ReductionProportion',
        },
        {
          title: '减免期限',
          align: 'center',
          dataIndex: 'ReductionTerm',
        },
        {
          title: '文件号',
          align: 'center',
          dataIndex: 'FileNumber',
        },
        {
          title: '文件内容',
          align: 'center',
          dataIndex: 'FileContents',
          scopedSlots: { customRender: 'ellipsis' },
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'WhetherExecutioOrZF',
          customRender: (text) => (
            <span class={text === '0' ? 'text-success' : 'text-error'}>{text === '0' ? '执行' : '作废'}</span>
          ),
        },
        {
          title: '制定时间',
          align: 'center',
          dataIndex: 'Timing',
          scopedSlots: { customRender: 'time' },
        },
        {
          title: '制定部门',
          align: 'center',
          dataIndex: 'FormulateDepartment',
        },
        {
          title: '修改时间',
          align: 'center',
          dataIndex: 'UpdateTime',
          scopedSlots: { customRender: 'time' },
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'Remark',
          scopedSlots: { customRender: 'ellipsis' },
        },
        {
          title: '操作',
          align: 'center',
          width: '80px',
          fixed: 'right',
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getRentReductStandardManage(requestParameters).then((res) => res)
      },
      editData: {},
      visibleForm: false,
      visibleDetail: false,
    }
  },
  methods: {
    handleSearch(values) {
      this.queryParam.standardName = values.standardName
      this.tableRefresh(true)
    },
    handleReset() {
      this.queryParam.standardName = ''
      this.tableRefresh(true)
    },
    tableRefresh(refresh = false) {
      this.$refs.table.refresh(refresh)
    },
    handleAction(record, type) {
      this.editData = record
      switch (type) {
        case 'detail':
          this.visibleDetail = true
          break
        case 'state':
          this.$loading.show({
            tip: '提交中，请稍后...',
          })
          postRentReductStandardManage({
            State: record.WhetherExecutioOrZF === '0' ? 'BQY' : 'QY',
            rentmanage: {
              ID: record.ID,
            },
          })
            .then((res) => {
              this.$message.success(`${record.WhetherExecutioOrZF === '0' ? '作废' : '启用'}成功！`)
              this.tableRefresh()
            })
            .finally(() => {
              this.$loading.hide()
            })

          break
        default:
          this.visibleForm = true
          break
      }
    },
  },
}
</script>
<style lang="less" scoped>
/deep/ .ant-table td {
  white-space: nowrap;
}
</style>
